package demoMod.invincibleOne.patches;

import com.badlogic.gdx.math.MathUtils;
import com.evacipated.cardcrawl.modthespire.lib.SpireInsertPatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.evacipated.cardcrawl.modthespire.lib.SpireReturn;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import demoMod.invincibleOne.InvincibleOneMod;
import demoMod.invincibleOne.cards.invincible.LatestAchievements;
import demoMod.invincibleOne.characters.InvincibleOne;

public class AbstractMonsterPatch {
    @SpirePatch(
            clz = AbstractMonster.class,
            method = "playBossStinger"
    )
    public static class PatchPlayBossStinger {
        public static SpireReturn<Void> Prefix() {
            if (AbstractDungeon.player instanceof InvincibleOne) {
                String bgmKey = null;
                switch (MathUtils.random(0, 3)) {
                    case 0:
                        bgmKey = "STS_DeathStinger_1_v3_MUSIC.ogg";
                        break;
                    case 1:
                        bgmKey = "STS_DeathStinger_2_v3_MUSIC.ogg";
                        break;
                    case 2:
                        bgmKey = "STS_DeathStinger_3_v3_MUSIC.ogg";
                        break;
                    case 3:
                        bgmKey = "STS_DeathStinger_4_v3_MUSIC.ogg";
                        break;
                }

                CardCrawlGame.music.playTempBgmInstantly(bgmKey, false);
                return SpireReturn.Return(null);
            }
            return SpireReturn.Continue();
        }
    }

    @SpirePatch(
            clz = AbstractMonster.class,
            method = "heal",
            paramtypez = {
                    int.class
            }
    )
    public static class PatchHeal {
        @SpireInsertPatch(rloc = 9)
        public static void Insert(AbstractMonster monster, int healAmount) {
            if (monster.currentHealth > monster.maxHealth && AbstractDungeon.player.masterDeck.group.stream().anyMatch(c -> c.cardID.equals(LatestAchievements.ID))) {
                monster.maxHealth = monster.currentHealth;
            }
            InvincibleOneMod.bingoPanel.getSlots().forEach(slot -> slot.getBingoItem().onMonsterHeal(monster, healAmount));
        }
    }
}
